<?php

/**
 * @author HungPV <phamvanhung0818@gmail.com>
 * @todo manager user model
 */
class user extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    /**
     * authen user for login
     * @param type $username
     * @param type $password
     * @return null
     */
    function authen($username, $password) {
        $password = md5($password);
        $query = $this->db->get_where('user', array('username' => $username, 'password' => $password));
        $result = $query->result();
        if (count($result) > 0) {
            return $result[0];
        } else {
            return null;
        }
    }

    /**
     * check user login
     * @return boolean
     */
    function check_permission() {
        if ($this->session->userdata('logined')) {
            return true;
        } else {
            redirect('administrator/login');
            return false;
        }
    }

}

?>
